package com.medical.mapi;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by junzi on 2016/10/17.
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.medical.mapi"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false)
                .globalResponseMessage(RequestMethod.GET, responseMessages());
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo(
                "Medical API",
                "会员用户数据接口",
                "v1.0",
                "会员服务",
                "jun2xu@qq.com",
                "License of YSH",
                "http://www.yilife.com/");
        return apiInfo;
    }

    private List<ResponseMessage> responseMessages(){
        List<ResponseMessage> rms = new ArrayList<>();
        rms.add(new ResponseMessageBuilder()
                .code(500)
                .message("系统出错")
                .build());
        rms.add(new ResponseMessageBuilder()
                        .code(403)
                        .message("拒绝访问")
                        .build());
        return rms;
    }
}